package com.sgcc.pda.mdrh.zoom.router;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;

import com.google.gson.Gson;
import com.sgcc.pda.gis.GisManager;
import com.sgcc.pda.gis.LocationCallback;
import com.sgcc.pda.hzaidl.entity.RequestBean;
import com.sgcc.pda.model.gis.GisCallbackRequest;
import com.sgcc.pda.model.gis.LocationResult;

/**
 * Created by cj on 2019/12/2.
 */
public class GisRouter extends BaseOperateRouter {

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
    @Override
    public String handleResult(Context context, final RequestBean requestBean, final CompleteListener completeListener) {
        String methodName = requestBean.getMethodName().split("_")[1];
        switch (methodName) {
            case "initMap":
                GisCallbackRequest gisCallbackRequest = new Gson().fromJson(requestBean.getParamJson(), GisCallbackRequest.class);
                GisManager.getInstance(context).initMap(gisCallbackRequest.getAuthKey());
                break;

            case "unInitMap":
                GisManager.getInstance(context).unInitMap();
                break;

            case "isInit":
               return GisManager.getInstance(context).isInit()+"";
            case "startLocate":
                GisManager.getInstance(context).startLocate();
                break;
            case "stopLocate":
                GisManager.getInstance(context).stopLocate();
                break;
            case "getLocation":
                GisManager.getInstance(context).getLocation(new LocationCallback.Stub() {
                    @Override
                    public void onResult(double lat, double lot) {
                        LocationResult locationResult = new LocationResult();
                        locationResult.setLat(lat);
                        locationResult.setLon(lot);
                        completeListener.complete(1,new Gson().toJson(locationResult));
                    }
                });
                break;
            case "getLastValidLocation":
                return GisManager.getInstance(context).getLastValidLocation();
            default:
                break;
        }
        return null;
    }


}
